using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_VKQADT
    {
        public DataRow Convert2ICC_VKQADT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_VKQADT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ROWNID"] = " ".PadRight(0 ); 
         dwReturn["ART"] = " ".PadRight(24 ); 
         dwReturn["COLOR"] = " ".PadRight(10 ); 
         dwReturn["TYP"] = " ".PadRight(10 ); 
         dwReturn["ITEM"] = " ".PadRight(5 ); 
         dwReturn["CLAF"] = " ".PadRight(10 ); 
         dwReturn["DESCR"] = " ".PadRight(20 ); 
         dwReturn["ROLL"] = " ".PadRight(0 ); 
         dwReturn["QTY"] = " ".PadRight(0 ); 
         dwReturn["DIFQTY"] = " ".PadRight(0 ); 
         dwReturn["DIFRATE"] = " ".PadRight(0 ); 
         dwReturn["DIFF"] = " ".PadRight(20 ); 
         dwReturn["JUDGE"] = " ".PadRight(20 ); 
         dwReturn["REQ"] = " ".PadRight(20 ); 
         dwReturn["PROCESS"] = " ".PadRight(50 ); 
         dwReturn["ZCPROC"] = " ".PadRight(50 ); 
         dwReturn["ZCUSER"] = " ".PadRight(8 ); 
         dwReturn["ZCDAT"] = " ".PadRight(20 ); 
         dwReturn["JPPROC"] = " ".PadRight(50 ); 
         dwReturn["JPUSER"] = " ".PadRight(8 ); 
         dwReturn["JPDAT"] = " ".PadRight(20 ); 
         dwReturn["DETL"] = " ".PadRight(100 ); 
         dwReturn["REMARK"] = " ".PadRight(200 ); 
         dwReturn["NEWUSER"] = " ".PadRight(8 ); 
         dwReturn["NEWTIME"] = " ".PadRight(20 ); 
         dwReturn["CHGUSER"] = " ".PadRight(8 ); 
         dwReturn["CHGTIME"] = " ".PadRight(20 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_VKQADT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_VKQADT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_VKQADT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_VKQADT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_VKQADT(dwLocal, ITXDBVERSION);
            }
            UpdateICC_VKQADT(dwLocal);
        }
        public void InsertICC_VKQADT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_VKQADT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_VKQADT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_VKQADT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_VKQADT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_VKQADT";
            Return = Result;
            return Return;
        }
        public void DeleteICC_VKQADT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_VKQADT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateICC_VKQADT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ICC_VKQADT SET "
                    +"ROWNID= :ROWNID,"
                    +"ART= :ART,"
                    +"COLOR= :COLOR,"
                    +"TYP= :TYP,"
                    +"ITEM= :ITEM,"
                    +"CLAF= :CLAF,"
                    +"DESCR= :DESCR,"
                    +"ROLL= :ROLL,"
                    +"QTY= :QTY,"
                    +"DIFQTY= :DIFQTY,"
                    +"DIFRATE= :DIFRATE,"
                    +"DIFF= :DIFF,"
                    +"JUDGE= :JUDGE,"
                    +"REQ= :REQ,"
                    +"PROCESS= :PROCESS,"
                    +"ZCPROC= :ZCPROC,"
                    +"ZCUSER= :ZCUSER,"
                    +"ZCDAT= :ZCDAT,"
                    +"JPPROC= :JPPROC,"
                    +"JPUSER= :JPUSER,"
                    +"JPDAT= :JPDAT,"
                    +"DETL= :DETL,"
                    +"REMARK= :REMARK,"
                    +"NEWUSER= :NEWUSER,"
                    +"NEWTIME= :NEWTIME,"
                    +"CHGUSER= :CHGUSER,"
                    +"CHGTIME= :CHGTIME,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString(); 
          or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"].ToString(); 
          or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString(); 
          or1.Parameters.Add("TYP", OracleType.NVarChar).Value = dwData["TYP"].ToString(); 
          or1.Parameters.Add("ITEM", OracleType.NVarChar).Value = dwData["ITEM"].ToString(); 
          or1.Parameters.Add("CLAF", OracleType.NVarChar).Value = dwData["CLAF"].ToString(); 
          or1.Parameters.Add("DESCR", OracleType.NVarChar).Value = dwData["DESCR"].ToString(); 
          or1.Parameters.Add("ROLL", OracleType.NVarChar).Value = dwData["ROLL"].ToString(); 
          or1.Parameters.Add("QTY", OracleType.NVarChar).Value = dwData["QTY"].ToString(); 
          or1.Parameters.Add("DIFQTY", OracleType.NVarChar).Value = dwData["DIFQTY"].ToString(); 
          or1.Parameters.Add("DIFRATE", OracleType.NVarChar).Value = dwData["DIFRATE"].ToString(); 
          or1.Parameters.Add("DIFF", OracleType.NVarChar).Value = dwData["DIFF"].ToString(); 
          or1.Parameters.Add("JUDGE", OracleType.NVarChar).Value = dwData["JUDGE"].ToString(); 
          or1.Parameters.Add("REQ", OracleType.NVarChar).Value = dwData["REQ"].ToString(); 
          or1.Parameters.Add("PROCESS", OracleType.NVarChar).Value = dwData["PROCESS"].ToString(); 
          or1.Parameters.Add("ZCPROC", OracleType.NVarChar).Value = dwData["ZCPROC"].ToString(); 
          or1.Parameters.Add("ZCUSER", OracleType.NVarChar).Value = dwData["ZCUSER"].ToString(); 
          or1.Parameters.Add("ZCDAT", OracleType.NVarChar).Value = dwData["ZCDAT"].ToString(); 
          or1.Parameters.Add("JPPROC", OracleType.NVarChar).Value = dwData["JPPROC"].ToString(); 
          or1.Parameters.Add("JPUSER", OracleType.NVarChar).Value = dwData["JPUSER"].ToString(); 
          or1.Parameters.Add("JPDAT", OracleType.NVarChar).Value = dwData["JPDAT"].ToString(); 
          or1.Parameters.Add("DETL", OracleType.NVarChar).Value = dwData["DETL"].ToString(); 
          or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString(); 
          or1.Parameters.Add("NEWUSER", OracleType.NVarChar).Value = dwData["NEWUSER"].ToString(); 
          or1.Parameters.Add("NEWTIME", OracleType.NVarChar).Value = dwData["NEWTIME"].ToString(); 
          or1.Parameters.Add("CHGUSER", OracleType.NVarChar).Value = dwData["CHGUSER"].ToString(); 
          or1.Parameters.Add("CHGTIME", OracleType.NVarChar).Value = dwData["CHGTIME"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
